package cn.itcast.bos.consumer;

import cn.itcast.bos.utils.Config;
import cn.itcast.bos.utils.HttpUtil;
import cn.itcast.bos.utils.SmsUtils;
import org.springframework.stereotype.Service;

import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.MessageListener;
import java.io.UnsupportedEncodingException;

@Service
//发送短信的类
public class SmsConsumer implements MessageListener {
    @Override
    public void onMessage(Message message) {
        MapMessage mapMessage = (MapMessage) message;

        try {
            String operation = "/industrySMS/sendSMS";
            String accountSid = Config.ACCOUNT_SID;
            String to = mapMessage.getString("telephone");
            String smsContent = "【速运快递】您的验证码为:{"+mapMessage.getString("msg")+"}，请于1分钟内正确输入，如非本人操作，请忽略此短信。";
            String body ="accountSid=" + accountSid + "&to=" + to + "&smsContent=" + smsContent+HttpUtil.createCommonParam();
            String url=Config.BASE_URL+operation;
            String result = HttpUtil.post(url,body);
            System.out.println(result);
        } catch (JMSException e) {
            e.printStackTrace();
        }


    }
}
